package com.jingyanzi.channel;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.jingyanzi.channel.domain.ChannelDO;
import com.jingyanzi.channel.domain.ChannelTypeDO;
import com.jingyanzi.channel.domain.ChannelWindowDO;
import com.jingyanzi.channel.result.ResultDO;
import com.jingyanzi.channel.result.ResultSupport;
import com.jingyanzi.channel.service.IChannelService;
import com.jingyanzi.channel.service.IChannelTypeService;
import com.jingyanzi.channel.service.IChannelWindowService;

@RestController
@RequestMapping("/api")
public class ChannelClientImpl {

	@Autowired
	private IChannelService channelService;
	
	@Autowired
	private IChannelWindowService channelWindowService;
	
	@Autowired
	private IChannelTypeService channelTypeService;
	
	@RequestMapping("/channel/{id}")
	public ChannelDO getChannel(@PathVariable(value = "id") Integer id) {
		ResultDO result = channelService.get(id);
		return (ChannelDO) result.getModel(ResultSupport.FIRST_MODEL_KEY);
	}
	
	@RequestMapping("/channelType/{id}")
	public ChannelTypeDO getChannelType(@PathVariable(value = "id") Integer id) {
		ResultDO result = channelTypeService.get(id);
		return (ChannelTypeDO) result.getModel(ResultSupport.FIRST_MODEL_KEY);
	}
	
	@RequestMapping("/channelWindow/{id}")
	public ChannelWindowDO getChannelWindow(@PathVariable(value = "id") Integer id) {
		ResultDO result = channelWindowService.get(id);
		return (ChannelWindowDO) result.getModel(ResultSupport.FIRST_MODEL_KEY);
	}
	
}
